package com.ca.project.web.Serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.util.Objects;

/**
 * 将前端返回的数据(Long)转化成JSON格式
 *
 * @PACKAGE_NAME: com.ca.project.web.Serializer
 * @NAME: IdEncryptSerializer
 * @USER: ASUS
 * @DATE: 2023/8/28
 * @TIME: 下午 03:25
 **/
public class IdEncryptSerializer extends JsonSerializer<Long> {

    /**
     * 序列化
     *
     * @param value
     * @param gen
     * @param serializers
     * @throws IOException
     */
    @Override
    public void serialize(Long value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        if (Objects.isNull(value)) {
            gen.writeString(StringUtils.EMPTY);
        } else {
            //gen.writeString(IdUtil.encrypt(value));
        }
    }

}